using System;
using ns18;
using ns20;

namespace Newtonsoft.Json.Linq
{
	public class JTokenReader : JsonReader, IJsonLineInfo
	{
		private readonly JToken jtoken_0;

		private JToken jtoken_1;

		private JToken jtoken_2;

		private bool Boolean_0 => jtoken_2 == jtoken_1;

		int IJsonLineInfo.LineNumber
		{
			get
			{
				if (base.CurrentState == State.Start)
				{
					return 0;
				}
				return ((IJsonLineInfo)(Boolean_0 ? null : jtoken_2))?.LineNumber ?? 0;
			}
		}

		int IJsonLineInfo.LinePosition
		{
			get
			{
				if (base.CurrentState == State.Start)
				{
					return 0;
				}
				return ((IJsonLineInfo)(Boolean_0 ? null : jtoken_2))?.LinePosition ?? 0;
			}
		}

		public JTokenReader(JToken token)
		{
			Class204.smethod_2(token, "token");
			jtoken_0 = token;
			jtoken_2 = token;
		}

		public override byte[] ReadAsBytes()
		{
			return method_5();
		}

		public override decimal? ReadAsDecimal()
		{
			return method_6();
		}

		public override int? ReadAsInt32()
		{
			return method_7();
		}

		public override string ReadAsString()
		{
			return method_8();
		}

		public override DateTime? ReadAsDateTime()
		{
			return method_9();
		}

		public override DateTimeOffset? ReadAsDateTimeOffset()
		{
			return method_4();
		}

		internal override bool Newtonsoft_002EJson_002EJsonReader_002E_202E_206F_206A_206A_202D_202B_206A_202E_206F_206F_200B_200B_200F_206D_200F_206F_200C_200E_202A_202E_202A_206C_202B_200C_202A_206E_200C_202C_200D_200E_202D_200C_206D_200F_202B_206A_206B_200D_206C_202D_202E()
		{
			if (base.CurrentState != 0)
			{
				JContainer jContainer = jtoken_2 as JContainer;
				if (jContainer != null && jtoken_1 != jContainer)
				{
					return method_17(jContainer);
				}
				return method_14(jtoken_2);
			}
			method_19(jtoken_2);
			return true;
		}

		public override bool Read()
		{
			enum14_0 = Enum14.Read;
			return Newtonsoft_002EJson_002EJsonReader_002E_202E_206F_206A_206A_202D_202B_206A_202E_206F_206F_200B_200B_200F_206D_200F_206F_200C_200E_202A_202E_202A_206C_202B_200C_202A_206E_200C_202C_200D_200E_202D_200C_206D_200F_202B_206A_206B_200D_206C_202D_202E();
		}

		private bool method_14(JToken jtoken_3)
		{
			if (jtoken_3 == jtoken_0)
			{
				return method_15();
			}
			JToken next = jtoken_3.Next;
			if (next != null && next != jtoken_3 && jtoken_3 != jtoken_3.Parent.Last)
			{
				jtoken_2 = next;
				method_19(jtoken_2);
				return true;
			}
			if (jtoken_3.Parent == null)
			{
				return method_15();
			}
			return method_18(jtoken_3.Parent);
		}

		private bool method_15()
		{
			SetToken(JsonToken.None);
			return false;
		}

		private JsonToken? method_16(JContainer jcontainer_0)
		{
			return jcontainer_0.Type switch
			{
				JTokenType.Object => JsonToken.EndObject, 
				JTokenType.Array => JsonToken.EndArray, 
				JTokenType.Constructor => JsonToken.EndConstructor, 
				JTokenType.Property => null, 
				_ => throw Class194.smethod_1("Type", jcontainer_0.Type, "Unexpected JContainer type."), 
			};
		}

		private bool method_17(JContainer jcontainer_0)
		{
			JToken first = jcontainer_0.First;
			if (first == null)
			{
				return method_18(jcontainer_0);
			}
			method_19(first);
			jtoken_2 = first;
			jtoken_1 = jcontainer_0;
			return true;
		}

		private bool method_18(JContainer jcontainer_0)
		{
			JsonToken? jsonToken = method_16(jcontainer_0);
			if (jsonToken.HasValue)
			{
				SetToken(jsonToken.Value);
				jtoken_2 = jcontainer_0;
				jtoken_1 = jcontainer_0;
				return true;
			}
			return method_14(jcontainer_0);
		}

		private void method_19(JToken jtoken_3)
		{
			switch (jtoken_3.Type)
			{
			default:
				throw Class194.smethod_1("Type", jtoken_3.Type, "Unexpected JTokenType.");
			case JTokenType.Object:
				SetToken(JsonToken.StartObject);
				break;
			case JTokenType.Array:
				SetToken(JsonToken.StartArray);
				break;
			case JTokenType.Constructor:
				SetToken(JsonToken.StartConstructor);
				break;
			case JTokenType.Property:
				SetToken(JsonToken.PropertyName, ((JProperty)jtoken_3).Name);
				break;
			case JTokenType.Comment:
				SetToken(JsonToken.Comment, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Integer:
				SetToken(JsonToken.Integer, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Float:
				SetToken(JsonToken.Float, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.String:
				SetToken(JsonToken.String, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Boolean:
				SetToken(JsonToken.Boolean, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Null:
				SetToken(JsonToken.Null, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Undefined:
				SetToken(JsonToken.Undefined, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Date:
				SetToken(JsonToken.Date, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Raw:
				SetToken(JsonToken.Raw, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Bytes:
				SetToken(JsonToken.Bytes, ((JValue)jtoken_3).Value);
				break;
			case JTokenType.Guid:
				SetToken(JsonToken.String, method_20(((JValue)jtoken_3).Value));
				break;
			case JTokenType.Uri:
				SetToken(JsonToken.String, method_20(((JValue)jtoken_3).Value));
				break;
			case JTokenType.TimeSpan:
				SetToken(JsonToken.String, method_20(((JValue)jtoken_3).Value));
				break;
			}
		}

		private string method_20(object object_1)
		{
			return object_1?.ToString();
		}

		bool IJsonLineInfo.HasLineInfo()
		{
			if (base.CurrentState == State.Start)
			{
				return false;
			}
			return ((IJsonLineInfo)(Boolean_0 ? null : jtoken_2))?.HasLineInfo() ?? false;
		}
	}
}
